'use strict';

angular.module('dashboard').controller('DashboardController', ['$rootScope', '$scope', '$stateParams', '$location', 'Authentication', 'Dashboard',
	function($rootScope, $scope, $stateParams, $location, Authentication, Dashboard) {
		$rootScope.authentication = Authentication;

		if(!$rootScope.authentication.user)
		{
			$location.path('/');
		}

		$scope.create = function() {
			var dashboard = new Dashboard({
				title: this.title,
				content: this.content
			});
			dashboard.$save(function(response) {
				$location.path('dashboard/' + response._id);

				$scope.title = '';
				$scope.content = '';
			}, function(errorResponse) {
				$scope.error = errorResponse.data.message;
			});
		};
	}
]);